﻿@model IEnumerable<DistributeTransaction.Models.ShoppingCart>
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var grid = new WebGrid(source: Model);
}
<h2>
    Shopping Cart</h2>
@using (Html.BeginForm())
{
    <fieldset>
        <legend></legend>
        @grid.GetHtml(
            tableStyle: "webgrid",
            headerStyle: "webgrid-heade",
            footerStyle: "webgrid-footer",
            alternatingRowStyle: "webgrid-alternating-row",
            selectedRowStyle: "webgrid-selected-row",
            rowStyle: "webgrid-row-style",
            displayHeader: true,
            columns: grid.Columns(
                grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", new { productID = item.ProductID })),
                grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { productID = item.ProductID })),
                grid.Column(
                             columnName: "ProductName",
                             header: "Product Name",
                             style: "text-align-center"
                            ),
                grid.Column(
                             columnName: "UnitPrice",
                             header: "Price",
                             style: "text-align-right"
                            ),
                grid.Column(
                            columnName: "Quantity",
                            header: "Quantity",
                            style: "text-align-right"
                        ),
                grid.Column(
                            columnName: "QuantityPerUnit",
                            header: "Decription",
                            style: "text-align-center"),
                grid.Column(
                            columnName: "CompanyName",
                            header: "Manufacturer",
                            style: "text-align-center"
                            )
                   )
        )
        <div>
            <p>
                @Html.Hidden("Amount", ViewBag.Amount as string)
                <b>Total: @ViewBag.Summary </b>
                <br />
            </p>
        </div>
        <div>
            @if (Model.Count() == 0)
            {
                <input type="submit" name="command" id="Empty_Cart" value="Empty Cart" disabled="disabled"/>
                <input type="submit" name="command" id="Check_Out" value="Check Out" disabled="disabled"/>
            }
            else
            {
                <input type="submit" name="command" id="EmptyCart" value="Empty Cart" />
                <input type="submit" name="command" id="CheckOut" value="Check Out" />
            }
        </div>
    </fieldset>
}
<script type="text/javascript" language="javascript">
    $(function () {
        $('#EmptyCart').click(function () {
            var ret = confirm('Are you sure you wish to empty shopping cart?');
            if (ret) {
                $('form').submit();
            }
            return ret;
        });
    });
</script>